/**
 * @file        bsp_led.c
 * @brief       单片机IO直驱的LED驱动
 * @version     V1.0
 * @author      Jsir2022 (jsir2022@outlook.com)
 * @date        2024-02-26 22:52:28
 * LastEditors  Jsir2022
 * LastEditTime 2024-02-27 11:12:34
 * history		版本	日期		作者		说明
 * 				V1.0	2024-2-27	Jsir2022	正式发布
 * Copyright (c) 2024 by Jsir2022, All Rights Reserved.
 * @verbatim
 * ==============================================================================
 *
 * ==============================================================================
 * @endverbatim
 */
#include "bsp_led.h"

typedef struct
{
    GPIO_TypeDef *GPIOx;
    uint16_t GPIO_Pin;
    GPIO_PinState ActiveLevel; // LED导通电平
    bool Active;               // 是否导通
} stLED_GPIO_List_type;
//=================================用户修改======================================
static stLED_GPIO_List_type s_LED_GL[] = {
    {LED_GREEN_GPIO_Port, LED_GREEN_Pin, GPIO_PIN_SET},
    {LED_WHITE_GPIO_Port, LED_WHITE_Pin, GPIO_PIN_SET},
    {LED_BLUE_GPIO_Port, LED_BLUE_Pin, GPIO_PIN_SET},
    {NULL}}; // 不能删，作为结尾
//===================================END========================================

/**
 * @brief   初始化LED，并使其全灭
 * @note
 * @return  {*}
 */
void LED_Init(void)
{
    for (uint8_t i = 0; s_LED_GL[i].GPIOx != NULL; i++)
    {
        LED_GPIO_WritePin(s_LED_GL[i].GPIOx, s_LED_GL[i].GPIO_Pin, !s_LED_GL[i].ActiveLevel);
        s_LED_GL[i].Active = false;
    }
}

/**
 * @brief   控制LED的状态
 * @note    
 * @param   {emLED_List_type} _LED 选择某个LED
 * @param   {emLED_State_type} _State 控制导通/不导通/翻转
 * @return  {*}
 */
void LED_Ctrl(emLED_List_type _LED, emLED_State_type _State)
{
    if (_LED >= LED_NONE)
    {
        return;
    }
    if (_State != LED_TOGGLE)
    {
        s_LED_GL[_LED].Active = (_State == LED_OFF) ? false : true;
    }
    else
    {
        s_LED_GL[_LED].Active = !s_LED_GL[_LED].Active;
    }
    LED_GPIO_WritePin(s_LED_GL[_LED].GPIOx, s_LED_GL[_LED].GPIO_Pin, (s_LED_GL[_LED].Active == false) ? !s_LED_GL[_LED].ActiveLevel : s_LED_GL[_LED].ActiveLevel);
}